package com.bysj.yqsht.service.impl;

import com.bysj.yqsht.bean.CheckallStudent;
import com.bysj.yqsht.bean.CheckallStudentExample;
import com.bysj.yqsht.bean.extend.CheckallStudentExtend;
import com.bysj.yqsht.dao.CheckallStudentMapper;
import com.bysj.yqsht.dao.extend.CheckallStudentExtendMapper;
import com.bysj.yqsht.service.ICheckallStudentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ICheckallStudentServiceImpl implements ICheckallStudentService {
    @Resource
    private CheckallStudentMapper checkallStudentMapper;
    @Resource
    private CheckallStudentExtendMapper checkallStudentExtendMapper;

    @Override
    public List<CheckallStudent> findAll() {
        CheckallStudentExample example = new CheckallStudentExample();
        return checkallStudentMapper.selectByExample(example);
    }

    @Override
    public List<CheckallStudentExtend> findWithAll(int pageNum, int limit) {
        PageHelper.startPage(pageNum,limit);
        CheckallStudentExample example = new CheckallStudentExample();
        List<CheckallStudentExtend> list1 = checkallStudentExtendMapper.findWithAll();
       PageInfo<CheckallStudentExtend> data = new PageInfo<CheckallStudentExtend>(list1);
        List<CheckallStudentExtend> list = data.getList();
        return list;
    }

    @Override
    public List<CheckallStudentExtend> findWithAllBy(Long studentId, Long classesId) {

        return checkallStudentExtendMapper.findWithAllBy(studentId,classesId);
    }

    @Override
    public void saveOrUpdate(CheckallStudent checkallStudent) {

        if(checkallStudent.getId() != null){
            checkallStudentMapper.updateByPrimaryKey(checkallStudent);
        } else {
            checkallStudentMapper.insert(checkallStudent);
        }

    }

    @Override
    public void deleteById(Long id) {
        checkallStudentMapper.deleteByPrimaryKey(id);
    }
}
